
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.RoleAuthority;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage RoleAuthority entities.
 * 
 */
@Repository("RoleAuthorityDAO")

@Transactional
public class RoleAuthorityDAOImpl extends AbstractJpaDao<RoleAuthority> implements RoleAuthorityDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			RoleAuthority.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new RoleAuthorityDAOImpl
	 *
	 */
	public RoleAuthorityDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findRoleAuthorityByMeno
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByMeno(String meno) throws DataAccessException {

		return findRoleAuthorityByMeno(meno, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByMeno
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByMeno(String meno, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByMeno", startResult, maxRows, meno);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findRoleAuthorityByAdd
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByAdd(Boolean add) throws DataAccessException {

		return findRoleAuthorityByAdd(add, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByAdd
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByAdd(Boolean add, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByAdd", startResult, maxRows, add);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findRoleAuthorityByDelete
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByDelete(Boolean delete) throws DataAccessException {

		return findRoleAuthorityByDelete(delete, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByDelete
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByDelete(Boolean delete, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByDelete", startResult, maxRows, delete);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllRoleAuthoritys
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findAllRoleAuthoritys() throws DataAccessException {

		return findAllRoleAuthoritys(-1, -1);
	}

	/**
	 * JPQL Query - findAllRoleAuthoritys
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findAllRoleAuthoritys(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllRoleAuthoritys", startResult, maxRows);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findRoleAuthorityByPrimaryKey
	 *
	 */
	@Transactional
	public RoleAuthority findRoleAuthorityByPrimaryKey(Integer id) throws DataAccessException {

		return findRoleAuthorityByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByPrimaryKey
	 *
	 */

	@Transactional
	public RoleAuthority findRoleAuthorityByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findRoleAuthorityByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.RoleAuthority) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRoleAuthorityByEdit
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByEdit(Boolean edit) throws DataAccessException {

		return findRoleAuthorityByEdit(edit, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByEdit
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByEdit(Boolean edit, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByEdit", startResult, maxRows, edit);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findRoleAuthorityByMenoContaining
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByMenoContaining(String meno) throws DataAccessException {

		return findRoleAuthorityByMenoContaining(meno, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByMenoContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByMenoContaining(String meno, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByMenoContaining", startResult, maxRows, meno);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * JPQL Query - findRoleAuthorityById
	 *
	 */
	@Transactional
	public RoleAuthority findRoleAuthorityById(Integer id) throws DataAccessException {

		return findRoleAuthorityById(id, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityById
	 *
	 */

	@Transactional
	public RoleAuthority findRoleAuthorityById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findRoleAuthorityById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.RoleAuthority) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRoleAuthorityByCheck
	 *
	 */
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByCheck(Boolean check) throws DataAccessException {

		return findRoleAuthorityByCheck(check, -1, -1);
	}

	/**
	 * JPQL Query - findRoleAuthorityByCheck
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RoleAuthority> findRoleAuthorityByCheck(Boolean check, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRoleAuthorityByCheck", startResult, maxRows, check);
		return new LinkedHashSet<RoleAuthority>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(RoleAuthority entity) {
		return true;
	}
}
